<?php
if(!isset($_SESSION)) 
	{ 
		session_start(); 
	}

$page = isset ( $_REQUEST["page"] ) ? intval ( $_REQUEST["page"] ) : 1;

$rows_per_page = 5;

$page_start = ( $page - 1 ) * $rows_per_page;
$page_end = $page * $rows_per_page; 

$sqllogoutin =mysql_query("select DATE_FORMAT(TimeLogIn,'%Y-%m-%d') as DateTime,DATE_FORMAT(TimeLogIn,'%H:%i:%s') as TimeLogIn,
			DATE_FORMAT(TimeLogOut,'%H:%i:%s') as TimeLogOut  
			from checklogtime where IDEmployee = '$id_employee' order by checklogtime.TimeLogIn desc LIMIT $page_start,$rows_per_page ");

?>

<style>
		.log td {
			text-align: center;
			width: 265px;
		}
</style>
<script type="text/javascript">
function onclickPage(idemp,page){
	var lang = '<?=$_SESSION['lang']?>';
	/*$.ajax({url:"privateinformation/process-page-loghistory.php?idemp="+idemp+"&newlang="+lang+"&page="+page, success:function(result){
		document.getElementById("contenthistory").innerHTML=result;
	}});*/
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
	    {
		    //alert(xmlhttp.responseText);
	        document.getElementById("contenthistory").innerHTML=xmlhttp.responseText;
	    }
	  }
	xmlhttp.open("GET","privateinformation/process-page-loghistory.php?idemp="+idemp+"&newlang="+lang+"&page="+page,true);
	xmlhttp.send();	
}
</script>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<div id="contains" style="background-color: #edf4f7;">

	<div class="title"></div>
	<div class="body" id="contenthistory">
		<div class="nav_top" style="width: 100%;">
       		<div class="nav_tit"><?php echo $l_menu_privateinfo;?></div>     
            <div class="rehome"><a href="mainPhone.php"><?php echo $l_menu?></a></div>       
       	</div>
		<div style="height: 10px;"></div>
		<div class="changePass">
		<span id="head"><?php echo $l_loginhistory?></span>
		<table id="listRequest" class="rf-dt" style="width: 100%;">
				<colgroup span="6"></colgroup>
				<thead class="rf-dt-thd">
					<tr class="rf-dt-shdr">
						<th class="rf-dt-shdr-c" scope="col" style="background-color: #eeeeee;width: 5%;font-size: 12px;"><?php echo $l_No."."?></th>
						<th class="rf-dt-shdr-c" scope="col" style="background-color: #eeeeee;width: 31%;font-size: 12px;"><?php echo $l_date?></th>
						<th class="rf-dt-shdr-c" scope="col" style="background-color: #eeeeee;width: 31%;font-size: 12px;"><?php echo $l_timelogin?></th>
						<th class="rf-dt-shdr-c" scope="col" style="background-color: #eeeeee;width: 31%;font-size: 12px;"><?php echo $l_timelogout?></th>
					</tr>
					<?php 
					$i=0;
					while ($row = mysql_fetch_array($sqllogoutin)){
					 $i++;
					 $indexlog = (($page-1)*30)+$i;
						?>
					<tr>
					<td class="rf-dt-shdr-c" scope="col" style="background-color: #ffffff;width: 5%;font-weight: normal;font-size: 12px;"><?php echo $indexlog?></td>
					<td class="rf-dt-shdr-c" scope="col" style="background-color: #ffffff;width: 31%;font-weight: normal;font-size: 12px;">
							<?php echo $row[DateTime]?></td>
					<td class="rf-dt-shdr-c" scope="col" style="background-color: #ffffff;width: 31%;font-weight: normal;font-size: 12px;">
							<?php echo $row[TimeLogIn]?></td>
					<td class="rf-dt-shdr-c" scope="col" style="background-color: #ffffff;width: 31%;font-weight: normal;font-size: 12px;">
							<?php if($row[TimeLogOut]==""){echo "Not logout";}else{ echo $row[TimeLogOut];}?></td>
					</tr>
					<?php }?>
					
					<tr class="trfoot">
                    	<td class="rf-dt-ftr-c" scope="colgroup" colspan="5">
                        	<div style="text-align: center; width: 100%">
				<?php 
				 $re = mysql_query("select DATE_FORMAT(TimeLogIn,'%Y-%m-%d') as DateTime,DATE_FORMAT(TimeLogIn,'%H:%i:%s') as TimeLogIn,
						DATE_FORMAT(TimeLogOut,'%H:%i:%s') as TimeLogOut  
						from checklogtime where IDEmployee = '1324623394669' order by checklogtime.TimeLogIn desc");
				 $number_of_page = ceil ( mysql_num_rows( $re ) / $rows_per_page ); 
				 
				 if ( $number_of_page > 1 ) 
														{ 
															if ($page==1)
																$p=2;
															else if ($page==$number_of_page)
																$p=$number_of_page-1;
															else $p=$page;
															if($page!=1){?>
																<a onclick="onclickPage('<?=$id_employee?>',<?=1?>);" ><span class='button_next'><?php echo "<<<";?></span> </a>
																<a onclick="onclickPage('<?=$id_employee?>',<?=($page-1)?>);" ><span class='button_next'><?php echo "<<";?></span> </a>
															<?php  }
															else{
																//echo "<span class='button_next'><<<</span>"; 
																//echo "<span class='button_next'><<</span>";
															}
															for ( $i = $p-1; $i <= $p+1; $i++ ) {	
																	if ($i<=$number_of_page && $i>0)
																	
																		if ($i==$page){
																			echo "<span class='button_next'><b>".$i."</b></span>"; 
																		}else{
																		?>
																			<a onclick="onclickPage('<?=$id_employee?>',<?=$i?>);" ><span class="button_next" style="color: #508e21;">
																			<?php 
																			echo $i;
																			?>
																			</span> </a>
																		<?php 
																		}
																	?>
																
															<?php 
																	}
																
																if($page!=$number_of_page){ ?>
																	<a onclick="onclickPage('<?=$id_employee?>',<?=($page+1)?>);"><span class='button_next'><?php echo ">>";?></span> </a>
																	<a onclick="onclickPage('<?=$id_employee?>',<?=$number_of_page?>);" ><span class='button_next'><?php echo ">>>";?></span> </a>
																<?php }
																else{
																	//echo "<span class='button_next'>>></span> ";
																	//echo "<span class='button_next'>>>></span> ";
																}
															}
														
															
															?>
				</div>
				</td>
				</tr>
				</thead>
		</table>
		</div>
	</div>
</div>